﻿Imports System.Data.SqlClient
Imports PhDir.DAL
Imports PhDir.Model
Imports PhDir.Repository
Imports PhDir.Repository.DataReader

Namespace Repository.Phone

    Public Class SelectAllPhones
        Implements ISelectAll(Of Model.Phone)

        Overridable Function SelectAll() As List(Of Model.Phone) _
            Implements ISelectAll(Of Model.Phone).SelectAll

            Dim sqlDataReader As SqlDataReader = Nothing
            Dim phoneReader As PhoneReader = New PhoneReader()
            Dim phones As List(Of Model.Phone) = New List(Of Model.Phone)

            Using dbConnection = New DbConnection(DbContext.PhoneContext)

                dbConnection.CommandText = StoredProceduresName.GetAllUsers
                sqlDataReader = dbConnection.ExecuteReader()

                While sqlDataReader.Read()
                    Dim phone = phoneReader.Read(sqlDataReader)
                    phones.Add(phone)
                End While

            End Using

            Return phones
        End Function
    End Class

End Namespace
